{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 第四次练习"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "+ 请务必交到exer4文件夹下，谢绝交到master下\n",
    "+ 请不要改动任何文件，拜托\n",
    "+ 请在10月30日前提交。"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "请写一下姓名和学号：\n",
    "+ 姓名  \n",
    "+ 学号"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 题目一\n",
    "一般的歌，分为主歌和副歌部分。副歌有重复，对比两大功能。这就是A－B的基本曲式形式结构。  \n",
    "请找一首你的主打歌，把歌词打印出来，重复的副歌部分，请写一个函数，调用函数打印出来。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "窗透初晓 日照西桥 云自摇\n",
      "想你当年荷风微摆的衣角\n",
      "木雕流金 岁月涟漪 七年前封笔\n",
      "因为我今生挥毫只为你\n",
      "雨打湿了眼眶 年年倚井盼归堂\n",
      "最怕不觉泪已拆两行\n",
      "我在人间彷徨 寻不到你的天堂\n",
      "东瓶西镜放 恨不能遗忘\n",
      "又是清明雨上折菊寄到你身旁\n",
      "把你最爱的歌来轻轻唱\n",
      "远方有琴 愀然空灵 声声催天雨\n",
      "涓涓心事说给自己听\n",
      "月影憧憧 烟火几重 烛花红\n",
      "红尘旧梦 梦断都成空\n",
      "雨打湿了眼眶 年年倚井盼归堂\n",
      "最怕不觉泪已拆两行\n",
      "我在人间彷徨 寻不到你的天堂\n",
      "东瓶西镜放 恨不能遗忘\n",
      "又是清明雨上折菊寄到你身旁\n",
      "把你最爱的歌来轻轻唱\n",
      "我在人间彷徨 寻不到你的天堂\n",
      "东瓶西镜放 恨不能遗忘\n",
      "又是清明雨上折菊寄到你身旁\n",
      "把你最爱的歌来轻轻唱\n"
     ]
    }
   ],
   "source": [
    "def chrous_song(song):\n",
    "    print(\"我在人间彷徨 寻不到你的天堂\\n东瓶西镜放 恨不能遗忘\\n又是清明雨上折菊寄到你身旁\\n把你最爱的歌来轻轻唱\")\n",
    "print(\"窗透初晓 日照西桥 云自摇\\n想你当年荷风微摆的衣角\\n木雕流金 岁月涟漪 七年前封笔\\n因为我今生挥毫只为你\\n雨打湿了眼眶 年年倚井盼归堂\\n最怕不觉泪已拆两行\")\n",
    "chrous_song(\"清明雨上\")\n",
    "print(\"远方有琴 愀然空灵 声声催天雨\\n涓涓心事说给自己听\\n月影憧憧 烟火几重 烛花红\\n红尘旧梦 梦断都成空\\n雨打湿了眼眶 年年倚井盼归堂\\n最怕不觉泪已拆两行\")\n",
    "chrous_song(\"清明雨上\")\n",
    "chrous_song(\"清明雨上\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 题目二\n",
    "请写一个函数，能够计算均值、样本方差和n(自己写公式哦)。\n",
    "每次输入十个以上的数字，能够输出上述三个统计量。\n",
    "至少调用两次。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 71,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "n=11\n",
      "mean=8.0\n",
      "方差和=110.00\n",
      "if you want get variance or standard deviation,please input it at the first place \n",
      "if you don not need it please input N\n",
      "if you want get max min and se,please input Y at the secend place\n",
      "if you don not need it please input N\n",
      "n=12\n",
      "mean=7.5\n",
      "方差和=143.00\n",
      "if you want get variance or standard deviation,please input it at the first place \n",
      "if you don not need it please input N\n",
      "方差=11.92\n",
      "if you want get max min and se,please input Y at the secend place\n",
      "if you don not need it please input N\n",
      "n=12\n",
      "mean=7.5\n",
      "方差和=143.00\n",
      "if you want get variance or standard deviation,please input it at the first place \n",
      "if you don not need it please input N\n",
      "标准差=3.45\n",
      "if you want get max min and se,please input Y at the secend place\n",
      "if you don not need it please input N\n",
      "n=12\n",
      "mean=7.5\n",
      "方差和=143.00\n",
      "if you want get variance or standard deviation,please input it at the first place \n",
      "if you don not need it please input N\n",
      "if you want get max min and se,please input Y at the secend place\n",
      "if you don not need it please input N\n",
      "最大值=13\n",
      "最小值=2\n",
      "标准误=0.9965217285917832\n"
     ]
    }
   ],
   "source": [
    "def example_function(Variance=None,others=None,*arg):\n",
    "    sum=0\n",
    "    n=0\n",
    "    s=0\n",
    "    for value in arg:\n",
    "        sum=sum+value\n",
    "        n=n+1\n",
    "    mean=sum/n\n",
    "    for value in arg:\n",
    "        s=s+(value-mean)**2\n",
    "    print(\"n=%s\"%n)\n",
    "    print('mean=%s'%mean)\n",
    "    print(\"方差和=%.2f\"%s)\n",
    "    print(\"if you want get variance or standard deviation,please input it at the first place \")\n",
    "    print(\"if you don not need it please input N\")\n",
    "    if Variance==\"variance\": ##对关键词参数的值进行判断，输入其他值则不显示\n",
    "        print(\"方差=%.2f\" %(s/n))\n",
    "    if Variance ==\"standard deviation\": ##对关键词参数的值进行判断，输入其他值则不显示\n",
    "         print(\"标准差=%.2f\" %pow((s/n),1/2))\n",
    "    print(\"if you want get max min and se,please input Y at the secend place\")\n",
    "    print(\"if you don not need it please input N\")\n",
    "    if others ==\"Y\":  ##对关键词参数的值进行判断，输入其他值则不显示\n",
    "        print(\"最大值=%s\"%max(arg))\n",
    "        print(\"最小值=%s\"%min(arg))\n",
    "        print(\"标准误=%s\"%pow((s/n**2),1/2))\n",
    "example_function(1,2,3,4,5,6,7,8,9,10,11,12,13)##第二题\n",
    "example_function(\"variance\",1,2,3,4,5,6,7,8,9,10,11,12,13)##第三题\n",
    "example_function(\"standard deviation\",1,2,3,4,5,6,7,8,9,10,11,12,13)##第三题\n",
    "example_function(\"N\",\"Y\",2,3,4,5,6,7,8,9,10,11,12,13)##第四题"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 题目三\n",
    "刚才那个函数，默认的是输出均值、样本方差和n，请在后面添加一个关键词参数，让这个函数可以选择输出样本标准差或方差。"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 题目四\n",
    "刚才那个函数，请再增加三个关键词参数，让这个参数可以选择输出均值的标准误、最大值、最小值或不输出这三个统计量。"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
